package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.ExamPaper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExamPaperMapper {

    // 查询全部试卷
    @Select("SELECT * FROM exam_papers")
    List<ExamPaper> selectAll();

    // 插入新试卷
    @Insert("INSERT INTO exam_papers (paper_name, course_id, total_score, time_limit, description, status) " +
            "VALUES (#{paperName}, #{courseId}, #{totalScore}, #{timeLimit}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "paperId")
    int insert(ExamPaper examPaper);

    // 修改试卷
    @Update("UPDATE exam_papers SET paper_name=#{paperName}, course_id=#{courseId}, total_score=#{totalScore}, " +
            "time_limit=#{timeLimit}, description=#{description}, status=#{status} " +
            "WHERE paper_id=#{paperId}")
    int update(ExamPaper examPaper);

    // 删除试卷
    @Delete("DELETE FROM exam_papers WHERE paper_id=#{paperId}")
    int deleteUser(int paperId);

    // ✅ 查询单个试卷（修正后的表名）
    @Select("SELECT * FROM exam_papers WHERE paper_id = #{paperId}")
    ExamPaper findById(@Param("paperId") Integer paperId);
}
